package com.escriba.spring.controller;



import java.util.HashMap;
import java.util.Map;

import org.directwebremoting.annotations.RemoteMethod;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.escriba.logic.form.Contact;

@Controller
@SessionAttributes
public class ContactController {

	@RequestMapping(value = "/addContact", method = RequestMethod.POST)
	public ModelAndView addContact(@ModelAttribute("contact")
							Contact contact, BindingResult result) {

		System.out.println("First Name:" + contact.getFirstname() +
					"Last Name:" + contact.getLastname());
		Map<String, String> map = new HashMap<String, String>();
		map.put("first", contact.getFirstname());
		map.put("last", contact.getLastname());
		return new ModelAndView("form/contactlist", "map",map);
	}

	@RequestMapping("/contacts")
	public ModelAndView showContacts() {

		return new ModelAndView("form/contact", "command", new Contact());
	}
	
	@RemoteMethod
	@RequestMapping("/test1.dwr")
	public String cadena(@ModelAttribute("contact")
			Contact contact, BindingResult result){
		System.out.println("First Name:" + contact.getFirstname() +
					"Last Name:" + contact.getLastname());
		/*Map<String, String> map = new HashMap<String, String>();
		map.put("first", contact.getFirstname());
		map.put("last", contact.getLastname());*/
		return contact.getFirstname() +" "+ contact.getLastname() ;
	}
}
